using System;
using System.Collections.Generic;
using System.Text;

namespace Core.Demo4
{
	public class Demo4
	{
		public void HikePay(IEnumerable<Employee> employees)
		{
			foreach (var employee in employees)
			{
				employee.IncrementSalary(500);
				employee.LastIncrementDate = DateTime.Now;
			}
			ReportEmployeeListWhoseSalaryIsRevised(employees);
			
		}

		private void ReportEmployeeListWhoseSalaryIsRevised(IEnumerable<Employee> employees)
		{
			var reportText = new StringBuilder();
			reportText.Append("<html>");
			reportText.Append("<body>");
			reportText.Append("	<table>");
			foreach (var employee in employees)
			{
				reportText.Append("		<tr>");
				reportText.AppendFormat("			<td>{0}</td>", employee.Id);
				reportText.AppendFormat("			<td>{0}</td>", employee.Name);
				reportText.AppendFormat("			<td>{0}</td>", employee.Salary);
				reportText.AppendFormat("			<td>{0}</td>", employee.LastIncrementDate.Value.Date);
				reportText.Append("		</tr>");
			}
			reportText.Append("	</table>");
			reportText.Append("</body>");
			reportText.Append("</html>");

			var emailSenderService = new EmailSenderService();
			emailSenderService.Send(reportText.ToString(), "mahendra.mavani@gmail.com");
		}


		public class Employee
		{
			public double Salary { get; set; }
			public Guid Id { get; set; }
			public string Name { get; set; }
			public DateTime? LastIncrementDate { get; set; }

			public void IncrementSalary(double amount)
			{
				if (LastIncrementDate == null
					|| LastIncrementDate.Value < DateTime.Now.AddYears(-1))
				{
					Salary += amount;
				}
			}
		}

	}

	public class EmailSenderService
	{
		public void Send(string mailBody, string recieverEmailAddress)
		{
			throw new ApplicationException("Bad Boy.. Never send mail from your tests");
		}
	}
}